﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using Projectmanagement.Utl;
using Projectmanagement.Entity;

namespace ProjectManagement.Models
{
    public class _Member : EntityBase
    {
        [Display(Name = "名称")]
        public string Name { get; set; }
          [Display(Name = "项目")]
        public virtual int? ProjectID { get; set; }

         [Display(Name = "是否激活")]
        public virtual bool IsActivated { get; set; }

         [Display(Name = "角色")]
         public string RolePM
         {
            get;set;
         }

         [Display(Name = "角色")]
         public int? RolePMID 
         {
             get;
             set;
         } 

        public IEnumerable<SelectListItem> GetProjectSelectListItems()
        {
            var selectList = CH.DB.Projects.ToList().Select(a => new SelectListItem
            {
                Text = a.Name,
                Value = a.ID.ToString(),
                Selected = (a.ID == ProjectID)
            });
            return selectList;
        }

        public IEnumerable<SelectListItem> GetEmployeeSelectListItems()
        {
           
            //var temp = CH.DB.EmployeeRolePMs.Distinct();
            //List<int?> list = new List<int?>();
            //foreach (var x in temp)
            //{
            //    list.Add(x.EmployeeID);
            //}
            //var data = (from x in CH.DBAccount.EmployeeRoles
            //            join y in list on x.ID equals y
            //            select x);

            var selectList = CH.DB.EmployeeRolePMs.Select(a => new SelectListItem
            {
                Text = a.Name,
                Value = a.Name
               // Selected = (a.AccountName == Name)
            });
            return selectList.OrderBy(o=>o.Text);
        }
    }

    public class _ProjectType:EntityBase
    {
        public string Name{get;set;}
    }

     public class _Area:EntityBase
    {
        public string Name{get;set;}
    }

    public class _Project : EntityBase
    {
        //唯一名称和唯一编号都是在项目报表统计使用的
        [Display(Name = "项目显示名"), Required]
        public string ProjectDisplayName { get; set; }

        [Display(Name = "项目名"), Required]
        public string Name { get; set; }

        [Display(Name = "项目类型")]
        public int? ProjectTypeID { get; set; }


        [Display(Name = "项目负责人")]
        public string Manager { get; set; }

        [Display(Name = "项目编号"), Required]
        public string ProjectCode { get; set; }

        [Display(Name = "市场部接口人")]
        public string Market { get; set; }

        [Display(Name = "会务部接口人")]
        public string Conference { get; set; }

        [Display(Name = "产品部接口人")]
        public string Product { get; set; }

        public virtual List<_Task> Tasks { get; set; }

        [Display(Name = "正在进行"), Required]
        public bool IsActived { get; set; }

        [Display(Name = "项目开始时间"), Required, DisplayFormat(DataFormatString = "{0:d}")]
        public DateTime StartDate { get; set; }

        [Display(Name = "项目结束时间"), Required, DisplayFormat(DataFormatString = "{0:d}")]
        public DateTime EndDate { get; set; }

        [Display(Name = "会议开始时间"), Required, DisplayFormat(DataFormatString = "{0:d}")]
        public DateTime ConferenceStartDate { get; set; }

        [Display(Name = "会议结束时间"), Required, DisplayFormat(DataFormatString = "{0:d}")]
        public DateTime ConferenceEndDate { get; set; }

        [Display(Name = "销售目标"), Required, DisplayFormat(DataFormatString = "{0:c}")]
        public decimal Target { get; set; }

        [Display(Name = "销售经理")]
        public string TeamLeader { get; set; }

        [Display(Name = "会议地址")]
        public string Location { get; set; }

        [Display(Name = "其它")]
        public string Others { get; set; }

        public virtual Area Area { get; set; }

        [Display(Name = "默认行业"), Required]
        public int? AreaID { get; set; }

        public IEnumerable<SelectListItem> GetProjectSelectListItems()
        {
            var selectList =CH.DB.ProjectTypes.ToList().Select(a => new SelectListItem
            {
                Text = a.Name,
                Value = a.ID.ToString()
            });
            return selectList;
        }

        public IEnumerable<SelectListItem> GetAreaSelectListItems()
        {
            var selectList = CH.DB.Areas.ToList().Select(a => new SelectListItem
            {
                Text = a.Name,
                Value = a.ID.ToString()
            });
            return selectList;
        }
    }


    public class _TaskState : EntityBase
    {
        public string Name { get; set; }

        public int Code { get; set; }
    }
}

    
       
  
